package com.ruoyi.common.utils;

import java.util.Random;

/**
 * 6位编码生成工具类
 * 格式：2位字母 + 4位数字 (如: AB1234, YZ6789)
 */
public class CodeGeneratorUtil {

    private static final String LETTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
    private static final String NUMBERS = "0123456789";
    private static final Random random = new Random();

    /**
     * 生成6位编码
     *
     * @return 6位编码字符串 (格式: XX9999)
     */
    public static String generateCode() {
        StringBuilder code = new StringBuilder();

        // 生成2位字母
        for (int i = 0; i < 2; i++) {
            int index = random.nextInt(LETTERS.length());
            code.append(LETTERS.charAt(index));
        }

        // 生成4位数字
        for (int i = 0; i < 4; i++) {
            int index = random.nextInt(NUMBERS.length());
            code.append(NUMBERS.charAt(index));
        }

        return code.toString();
    }

    public static String generateBatchCode() {
        StringBuilder batchCode = new StringBuilder();
        batchCode.append("BC_");

        // 生成2位字母
        for (int i = 0; i < 2; i++) {
            int index = random.nextInt(LETTERS.length());
            batchCode.append(LETTERS.charAt(index));
        }

        // 生成4位数字
        for (int i = 0; i < 4; i++) {
            int index = random.nextInt(NUMBERS.length());
            batchCode.append(NUMBERS.charAt(index));
        }
        return batchCode.toString();
    }
}